import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    count: 0
  },
  mutations: {
    increment (state, payload) {
      state.count++
    },
    addN (state, obj) {
      state.count = state.count + obj.n
    }
  },
  actions: {
    add (context, obj) {
      // this.state.count = this.state.count + obj.n
      context.state.count = context.state.count + obj.n
    },
    addN (context, obj) {
      context.commit('addN', obj)
    }
  },
  getters: {
    count: state => state.count
  },
  modules: {
  }
})
